package features;

import javax.swing.JOptionPane;
import javax.swing.JTextPane;

public class Find_Next extends Find{
	
	public JTextPane textPane;
	
	public Find_Next(JTextPane textPane){
		this.textPane = textPane;
	}
	
	public void find_next() {
		int cont = 0;
		word = JOptionPane.showInputDialog("Type the word to find");
		findIndex = textPane.getText().indexOf(word);

		if (findIndex == -1) {
			show_word_not_find();
		} else {
			while (findIndex < textPane.getText().length() && findIndex != -1) {
				selectFound(textPane);
				cont++;

				findIndex = findIndex + word.length();

				findIndex = textPane.getText().indexOf(word, findIndex);

				int response = JOptionPane.showConfirmDialog(null,
						"Find next match?", "FindNext",
						JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE,
						null);

				if (response == JOptionPane.NO_OPTION) {
					break;
				}
			}

			JOptionPane.showMessageDialog(null,
					"End of text! \nNumber of matches: " + cont);
		}
	}
}
